﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.Mail;
using CE.Image;
using CE.Database;
using CE.AreaCountry;
using CE.Global;
using CE.PersonalAccident;
using CE.PostCode;
using CE.TravelInsurance;
using CE.User;
using CE.Security;
using CE.StreetDirectory;
using CE.Payment;

//using au.com.aceinsurance.tsuat; //TEST
using com.acegroup.travel.receive;  //LIVE

public partial class travel_insurance_proposalforms_ace_proposal_form : System.Web.UI.Page
{
    string _PlanName = "";
    string _TripType = "";
    Int64 _AreaID = 0;
    Int64 _CountryID = 0;
    string _InsuredType = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["mtaid"] != null && Request.QueryString["mpid"] != null
           && Request.QueryString["muid"] != null && Request.QueryString["mtarid"] != null && Request.QueryString["mplan"] != null)
        {
            if (Session["PlanType"] == null)
                Session["PlanType"] = Request.QueryString["mplan"].ToString();

            Session[CE.Global.General.TAId] = Request.QueryString["mtaid"].ToString();
            Session[General.ProviderCompanyId] = Request.QueryString["mpid"].ToString();            
            Session[CE.Global.General.TAResultId] = Request.QueryString["mtarid"].ToString();

            if (Request.QueryString["muid"].ToString() != "0")
                Session[General.UserId] = Request.QueryString["muid"].ToString();
        }

        if (Session[CE.Global.General.TAId] == null)
        {
            //Response.Redirect("~/travel-insurance/travel-quote.aspx");
            Response.Redirect("~/travel-insurance/");

        }

        if (Session[CE.Global.General.TAId] != null)
        {
            if (Session[General.ProviderCompanyId] == null)
            {
                Response.Redirect("~/travel-insurance/results.aspx");
            }
            if (Session[General.ProviderCompanyId].ToString() != "36")
            {
                Response.Redirect("~/travel-insurance/results.aspx");
            }
        }
        else
        {
            Response.Redirect("~/user/viewresulthistory.aspx");
        }

        if (!Page.IsPostBack)
        {
            lblProvider.Text = "ACE Insurance";
            //ClearSession();
            ChangeDateSettings();
            LoadSummary();

            #region Validation Effect
            txtFirstname.Attributes.Add("onblur", "ShowValidationEffect('" + txtFirstname.ClientID + "','" + rfvFirstname.ClientID + "')");
            txtSurname.Attributes.Add("onblur", "ShowValidationEffect('" + txtSurname.ClientID + "','" + rfvSurname.ClientID + "')");
            txtEmailAddress.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtEmailAddress.ClientID + "','" + rfvEmailAddress.ClientID + "','" + revEmailAddress.ClientID + "')");

            txtNameOfInsured.Attributes.Add("onblur", "ShowValidationEffect('" + txtNameOfInsured.ClientID + "','" + rfvNameOfInsured.ClientID + "')");
            txtInsured.Attributes.Add("onblur", "ShowValidationEffect('" + txtInsured.ClientID + "','" + rfvInsured.ClientID + "')");
            txtSpouse.Attributes.Add("onblur", "ShowValidationEffect('" + txtSpouse.ClientID + "','" + rfvSpouse.ClientID + "')");

            txtNameOfInsuredGiven.Attributes.Add("onblur", "ShowValidationEffect('" + txtNameOfInsuredGiven.ClientID + "','" + rfvNameOfInsuredGiven.ClientID + "')");
            txtInsuredGiven.Attributes.Add("onblur", "ShowValidationEffect('" + txtInsuredGiven.ClientID + "','" + rfvInsuredGiven.ClientID + "')");
            txtSpouseGiven.Attributes.Add("onblur", "ShowValidationEffect('" + txtSpouseGiven.ClientID + "','" + rfvSpouseGiven.ClientID + "')");

            txtNoOfChild.Attributes.Add("onblur", "ShowValidationEffect('" + txtNoOfChild.ClientID + "','" + rfvNoOfChild.ClientID + "')");

            txtNameoftheCard.Attributes.Add("onblur", "ShowValidationEffect('" + txtNameoftheCard.ClientID + "','" + rfvNameoftheCard.ClientID + "')");
            txtIssuingBank.Attributes.Add("onblur", "ShowValidationEffect('" + txtIssuingBank.ClientID + "','" + rfvIssuingBank.ClientID + "')");
            txtCardNo1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo1.ClientID + "','" + rfvCardNo1.ClientID + "','" + revCardNo1.ClientID + "')");
            txtCardNo2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo2.ClientID + "','" + rfvCardNo2.ClientID + "','" + revCardNo2.ClientID + "')");
            txtCardNo3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo3.ClientID + "','" + rfvCardNo3.ClientID + "','" + revCardNo3.ClientID + "')");
            txtCardNo4.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo4.ClientID + "','" + rfvCardNo4.ClientID + "','" + revCardNo4.ClientID + "')");
            ddlCardExpiryMonth.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCardExpiryMonth.ClientID + "','" + rfvCardExpiryMonth.ClientID + "')");
            ddlCardExpiryYear.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCardExpiryYear.ClientID + "','" + rfvCardExpiryYear.ClientID + "')");

            txtChildName1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName1.ClientID + "','" + rfvChildName1.ClientID + "','" + revChildName1.ClientID + "')");
            txtChildName2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName2.ClientID + "','" + rfvChildName2.ClientID + "','" + revChildName2.ClientID + "')");
            txtChildName3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName3.ClientID + "','" + rfvChildName3.ClientID + "','" + revChildName3.ClientID + "')");
            txtChildName4.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName4.ClientID + "','" + rfvChildName4.ClientID + "','" + revChildName4.ClientID + "')");
            txtChildName5.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName5.ClientID + "','" + rfvChildName5.ClientID + "','" + revChildName5.ClientID + "')");

            txtChildName1Given.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName1Given.ClientID + "','" + rfvChildName1Given.ClientID + "','" + revChildName1Given.ClientID + "')");
            txtChildName2Given.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName2Given.ClientID + "','" + rfvChildName2Given.ClientID + "','" + revChildName2Given.ClientID + "')");
            txtChildName3Given.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName3Given.ClientID + "','" + rfvChildName3Given.ClientID + "','" + revChildName3Given.ClientID + "')");
            txtChildName4Given.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName4Given.ClientID + "','" + rfvChildName4Given.ClientID + "','" + revChildName4Given.ClientID + "')");
            txtChildName5Given.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName5Given.ClientID + "','" + rfvChildName5Given.ClientID + "','" + revChildName5Given.ClientID + "')");

            rdoVisa.Attributes.Add("onblur", "CheckCardTypeValidationCss();");
            rdoMasterCard.Attributes.Add("onblur", "CheckCardTypeValidationCss();");
            //rdoAmex.Attributes.Add("onblur", "CheckCardTypeValidationCss();");
            //rdoJcb.Attributes.Add("onblur", "CheckCardTypeValidationCss();");
            //rdoDiners.Attributes.Add("onblur", "CheckCardTypeValidationCss();");
            #endregion

            txtUnit2.Attributes.Add("onkeyup", "ShowHideDiv('divInsured',true);");

            int _year;
            int startyear = CE.Global.General.GetUTCDateTime().Year;
            int endyear = CE.Global.General.GetUTCDateTime().Year + 10;
            for (_year = endyear; _year >= startyear; _year--)
            {
                ddlCardExpiryYear.Items.Insert(0, new ListItem(_year.ToString("0000"), _year.ToString("00")));
            }
            ddlCardExpiryYear.Items.Insert(0, new ListItem("yyyy", "-1"));

            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();


            if (Session[General.UserId] != null)
            {
                ShowUserDetails();
            }
            else if (Session[General.TAPersonnelId] != null
                && Session[General.TAUserName] != null
                && Session[General.TAPhoneNo] != null
                && Session[General.TAEmail] != null)
            {
                txtFirstname.Text = Session[General.TAUserName].ToString();
                txtMobileNo.PhoneNo = Session[General.TAPhoneNo].ToString();
                txtEmailAddress.Text = Session[General.TAEmail].ToString();
                
                txtInsuredGiven.Text = Session[General.TAUserName].ToString();
                txtNameOfInsuredGiven.Text = Session[General.TAUserName].ToString();
            }
        }
        //if (rdoVisa.Checked || rdoMasterCard.Checked || rdoAmex.Checked || rdoJcb.Checked || rdoDiners.Checked) txtCardType.Text = "1";
        if (rdoVisa.Checked || rdoMasterCard.Checked) txtCardType.Text = "1";


    }

    protected void LoadSummary()
    {
        Int64 TAId = 0;

        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

        if (Session[General.TAId] != null)
            TAId = Convert.ToInt64(Session[General.TAId]);

        _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

        if (_taapplicantsearch != null)
        {

            txtNoOfTravellers.Text = _taapplicantsearch.NoOfTravellers.ToString();
            txtNoOfChild.Text = _taapplicantsearch.NoofChilds.ToString();
            txtNoOfAdult.Text = _taapplicantsearch.NoofAdults.ToString();

            string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));
            lblQref.Text = "TIA" + convertno;
            lblPolicyType.Text = GetPolicy(_taapplicantsearch.PlanType.ToString());
            lblTrip.Text = _taapplicantsearch.TripType.ToString();
            lblCover.Text = _taapplicantsearch.CoverageLevel.ToString();
            lblCoverageType.Text = GetCoverage(_taapplicantsearch.TripType.ToString());
            lblCoverage.Text = _taapplicantsearch.CoverageLevel.ToString();
            lblTotalPremium.Text = "$ " + _taapplicantsearch.TotalPremium.ToString();
            lblNoOfTravellers.Text = _taapplicantsearch.NoOfTravellers.ToString();
            inNoOfTravellers.Value = _taapplicantsearch.NoOfTravellers.ToString();
            //lblInsCoverage.Text = GetPlanName(_taapplicantsearch.PlanType.ToString(), _taapplicantsearch.CoverageLevel.ToString());
            lblDuration.Text = _taapplicantsearch.Duration.ToString();
            lblAdultAge.Text = _taapplicantsearch.AdultAge.ToString();
            lblChildAge.Text = _taapplicantsearch.ChildAge.ToString();

            inPlanName.Value = _taapplicantsearch.Info2.Trim();
            inTripType.Value = _taapplicantsearch.TripType.Trim();
            inCountryId.Value = _taapplicantsearch.CountryID.ToString();
            inInsuredType.Value = _taapplicantsearch.PlanType.Trim();


            usrDOBPolicyHolder.Year = _taapplicantsearch.DOBAdult1.Year;
            usrDOBPolicyHolder.Month = _taapplicantsearch.DOBAdult1.Month;
            usrDOBPolicyHolder.Day = _taapplicantsearch.DOBAdult1.Day;

            if (txtNoOfAdult.Text.Trim() == "1")
            {
                usrDOB.Year = _taapplicantsearch.DOBAdult1.Year;
                usrDOB.Month = _taapplicantsearch.DOBAdult1.Month;
                usrDOB.Day = _taapplicantsearch.DOBAdult1.Day;
                usrDOB.IsEnabled = false;
            }
            else
            {
                usrDOBinsured.Year = _taapplicantsearch.DOBAdult1.Year;
                usrDOBinsured.Month = _taapplicantsearch.DOBAdult1.Month;
                usrDOBinsured.Day = _taapplicantsearch.DOBAdult1.Day;
                usrDOBinsured.IsEnabled = false;

                usrDOBSpouse.Year = _taapplicantsearch.DOBAdult2.Year;
                usrDOBSpouse.Month = _taapplicantsearch.DOBAdult2.Month;
                usrDOBSpouse.Day = _taapplicantsearch.DOBAdult2.Day;
                usrDOBSpouse.IsEnabled = false;

            }


            lblPeriodOfCoverage.Text = String.Format("{0:dd/MM/yyyy} To {1:dd/MM/yyyy}", _taapplicantsearch.StartDate, _taapplicantsearch.EndDate);
            lblStart.Text = _taapplicantsearch.StartDate.ToString();
            lblEnd.Text = _taapplicantsearch.EndDate.ToString();

            if (_taapplicantsearch.TripType == "A")
            {
                //lblPeriodOfCoverage.Text = String.Format("{0:dd/MM/yyyy}", _taapplicantsearch.StartDate);            
                inAreaId.Value = _taapplicantsearch.AreaID.ToString();
            }
            else
            {
                //lblPeriodOfCoverage.Text = String.Format("{0:dd/MM/yyyy} To {1:dd/MM/yyyy}", _taapplicantsearch.StartDate, _taapplicantsearch.EndDate);
                //lblStart.Text = _taapplicantsearch.StartDate.ToString();
                //lblEnd.Text = _taapplicantsearch.EndDate.ToString();

                inAreaId.Value = (GetAreaIdByCountryID(_taapplicantsearch.CountryID)).ToString();

            }

            if (_taapplicantsearch.AreaID != 0)
                lblDestination.Text = GetAreaName(_taapplicantsearch.AreaID);
            else
                lblDestination.Text = GetCountryName(_taapplicantsearch.CountryID);


            Int32 _AdultCount = Convert.ToInt32(txtNoOfAdult.Text.Trim());

            Int32 _ChildCount = Convert.ToInt32(txtNoOfChild.Text.Trim());
            if (_ChildCount > 0)
            {
                ddlChildDOB1.Day = _taapplicantsearch.DOBChild1.Day;
                ddlChildDOB1.Month = _taapplicantsearch.DOBChild1.Month;
                ddlChildDOB1.Year = _taapplicantsearch.DOBChild1.Year;

                ddlChildDOB2.Day = _taapplicantsearch.DOBChild2.Day;
                ddlChildDOB2.Month = _taapplicantsearch.DOBChild2.Month;
                ddlChildDOB2.Year = _taapplicantsearch.DOBChild2.Year;

                ddlChildDOB3.Day = _taapplicantsearch.DOBChild3.Day;
                ddlChildDOB3.Month = _taapplicantsearch.DOBChild3.Month;
                ddlChildDOB3.Year = _taapplicantsearch.DOBChild3.Year;

                ddlChildDOB4.Day = _taapplicantsearch.DOBChild4.Day;
                ddlChildDOB4.Month = _taapplicantsearch.DOBChild4.Month;
                ddlChildDOB4.Year = _taapplicantsearch.DOBChild4.Year;

                ddlChildDOB5.Day = _taapplicantsearch.DOBChild5.Day;
                ddlChildDOB5.Month = _taapplicantsearch.DOBChild5.Month;
                ddlChildDOB5.Year = _taapplicantsearch.DOBChild5.Year;

                ddlChildDOB6.Day = _taapplicantsearch.DOBChild6.Day;
                ddlChildDOB6.Month = _taapplicantsearch.DOBChild6.Month;
                ddlChildDOB6.Year = _taapplicantsearch.DOBChild6.Year;


                pnlChildsParticulars.Visible = true;
                if (_ChildCount == 1)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = false;
                    pnlChild3.Visible = false;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(false);
                    ValidateChild3(false);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 2)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = false;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(false);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 3)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 4)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 5)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = true;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(true);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 6)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = true;
                    pnlChild6.Visible = true;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(true);
                    ValidateChild6(true);
                }
            }
            else
            {
                pnlChildsParticulars.Visible = false;
                ValidateChild1(false);
                ValidateChild2(false);
                ValidateChild3(false);
                ValidateChild4(false);
                ValidateChild5(false);
                ValidateChild6(false);
            }

        }
    }

    protected string GetPlanName(string plantype, string coveragelevel)
    {
        string planname = "";
        TAQuoteResult _taresult = new TAQuoteResult();
        TAQuoteResultDB _tadb = new TAQuoteResultDB();

        _taresult = _tadb.GetTASelectSingleItemSelected(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), GetPolicy(plantype), coveragelevel);

        if (_taresult != null)
        {
            planname = _taresult.PlanName;
        }

        return planname;
    }

    protected string GetPolicy(string covertype)
    {
        string policy = "family";
        divIndividual.Visible = false;
        divWithspouse.Visible = false;

        if (covertype == "IND")
        {
            policy = "Individual";
            divIndividual.Visible = true;
        }
        else if (covertype == "INS")
        {
            policy = "Individual + Spouse";
            divWithspouse.Visible = true;
        }
        else if (covertype == "INC")
        {
            policy = "Individual + Child";
            divIndividual.Visible = true;
        }
        else if (covertype == "FML")
        {
            policy = "Family";

            if (txtNoOfAdult.Text != "1")
            {
                divWithspouse.Visible = true;
            }
            else
            {
                divIndividual.Visible = true;

            }
        }

        return policy;
    }

    protected string GetCoverage(string coverage)
    {
        string cover = "Single Trip";

        if (coverage == "A")
            cover = "Annual Multi-trip";

        return cover;
    }

    protected string GetCoverageLevel(string coverage)
    {
        string coveragelevel = "Standard";

        if (coverage == "STD")
            coveragelevel = "Standard";
        else if (coverage == "MED")
            coveragelevel = "Medium";
        else if (coverage == "HGH")
            coveragelevel = "High";

        return coveragelevel;
    }

    protected string GetAreaName(Int64 areaid)
    {
        string Area = "";

        AreaInfo _areainfo = new AreaInfo();
        AreaInfoDB _areainfodb = new AreaInfoDB();

        _areainfo = _areainfodb.GetAreaInfo(areaid);

        Area = _areainfo.Description;

        return Area;

    }

    protected string GetCountryName(Int64 countryid)
    {
        string Country = "";

        CountryInfo _countryinfo = new CountryInfo();
        CountryInfoDB _countryinfodb = new CountryInfoDB();

        _countryinfo = _countryinfodb.GetCountryInfo(countryid);

        Country = _countryinfo.Description;

        return Country;

    }

    protected Int64 GetAreaIdByCountryID(Int64 countryid)
    {
        Int64 AreaID = 0;

        AreaCountryInfoDB _areacountryinfodb = new AreaCountryInfoDB();
        AreaID = _areacountryinfodb.GetAreaIDByCountryID(countryid);

        return AreaID;
    }

    protected void ibtSubmit_Click(object sender, ImageClickEventArgs e)
    {
        lblMessage.Text = "";
        CheckValidation();
        ChangeValidationEffectServerSide("travel_insurance");

        if (IsValid)
        {
            string[] _acemessage = new string[2];

            if (inInsuredType.Value.Trim() == "INS")
            {
                _acemessage = SendToACE(true);
            }
            else
            {
                _acemessage = SendToACE(false);
            }

            if (_acemessage[0] == "Success" && _acemessage[1] == "Policy Accepted")
            {

                Int64 _tamoreresult = 0;
                TAMoreDetailAce _TAMoreDetailAce = new TAMoreDetailAce();
                TAMoreDetailAceDB _TAMoreDetailAcedb = new TAMoreDetailAceDB();

                _TAMoreDetailAce.cetaMoreDetailId = 0;
                _TAMoreDetailAce.cetaInsId = Convert.ToInt64(Session[General.TAResultId].ToString());
                _TAMoreDetailAce.cetaId = Convert.ToInt64(Session[General.TAId].ToString()); //TAAppSeaID 
                _TAMoreDetailAce.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
                _TAMoreDetailAce.Name = txtSurname.Text.ToUpper() + " " + txtFirstname.Text.ToUpper();
                _TAMoreDetailAce.PostalCode = txtPostCode.Text;
                _TAMoreDetailAce.UnitNo = txtUnit1.Text.Trim();
                _TAMoreDetailAce.HomeNo = txtUnit2.Text.Trim();
                _TAMoreDetailAce.Address = txtAddress.Text.Trim();
                _TAMoreDetailAce.NRICNo = ddlNRICPolicyHolder.GetIdNumber();
                _TAMoreDetailAce.Nationality = ddlNationality.GetNationality();
                _TAMoreDetailAce.MobileNo = txtMobileNo.GetPhoneNo();
                _TAMoreDetailAce.HomePhoneNo = txtResidentialPhoneNo.GetPhoneNo();
                _TAMoreDetailAce.OfficePhoneNo = txtOfficeNo.GetPhoneNo();
                _TAMoreDetailAce.FaxNo = "";
                _TAMoreDetailAce.Email = txtEmailAddress.Text;
                _TAMoreDetailAce.EmpName = "";
                //_TAMoreDetailAce.PlanName = lblInsCoverage.Text;
                _TAMoreDetailAce.PlanType = lblPolicyType.Text;
                _TAMoreDetailAce.TripType = lblTrip.Text;
                _TAMoreDetailAce.CoverageLevel = lblCover.Text;
                _TAMoreDetailAce.Country = lblDestination.Text;
                _TAMoreDetailAce.Area = lblDestination.Text;
                _TAMoreDetailAce.Duration = lblDuration.Text;
                _TAMoreDetailAce.StartDate = DateTime.Parse(lblStart.Text);
                _TAMoreDetailAce.EndDate = DateTime.Parse(lblEnd.Text);
                _TAMoreDetailAce.AdultAge = Convert.ToInt32(lblAdultAge.Text);
                _TAMoreDetailAce.ChildAge = Convert.ToInt32(lblChildAge.Text);
                _TAMoreDetailAce.NoOfTraveller = Convert.ToInt32(lblNoOfTravellers.Text);
                _TAMoreDetailAce.TotalPremium = float.Parse(lblTotalPremium.Text.Remove(0, 2));
                _TAMoreDetailAce.PamentType = "CreditCard";
                //_TAMoreDetailAce.Info1 = txtEmailAddress.Text;
                //_TAMoreDetailAce.Info2 = Session[General.TAId].ToString(); //AppSeaID

                if (Session[General.UserId] != null)
                    _TAMoreDetailAce.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                else
                    _TAMoreDetailAce.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());


                _TAMoreDetailAce.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                _TAMoreDetailAce.Status = true;

                _tamoreresult = _TAMoreDetailAcedb.Insert(_TAMoreDetailAce);

                Int64 TATraId = 0;
                if (_tamoreresult > 0)
                {
                    Int64 _paymentresult = 0;
                    Payment _payment = new Payment();
                    PaymentDB _paymentdb = new PaymentDB();

                    _payment.CXPaymentId = 0;
                    _payment.RefId = Convert.ToInt64(Session[General.TAId].ToString()); //_tamoreresult; 
                    _payment.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
                    _payment.InsuranceType = "TI";
                    _payment.NameoftheCard = txtNameoftheCard.Text.ToUpper();
                    _payment.IssuingBankName = txtIssuingBank.Text.Trim();
                    _payment.CreditCardNo = txtCardNo1.Text.Trim() + "" + txtCardNo2.Text.Trim() + "" + txtCardNo3.Text.Trim() + "" + txtCardNo4.Text.Trim();
                    _payment.CardExpiryMonth = ddlCardExpiryMonth.Text;
                    _payment.CardExpiryYear = ddlCardExpiryYear.Text;
                    if (rdoVisa.Checked == true)
                    {
                        _payment.CardType = "Visa";
                    }
                    else
                    {
                        _payment.CardType = "MasterCard";
                    }
                    _payment.Status = true;
                    if (Session[CE.Global.General.UserId] != null)
                    {
                        _payment.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                    }
                    else
                    {
                        _payment.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());
                    }

                    _paymentresult = _paymentdb.Insert(_payment);

                    if (_paymentresult > 0)
                    {
                        //Save Travellers to Insure

                        int NoOfTravellers = 0; // Convert.ToInt32(lblNoOfTravellers.Text.ToString());

                        string salutation = "";
                        string idtype = "";
                        string gender = "";
                        string surname = "";
                        string givenname = "";
                        string idnum = "";
                        DateTime birthday = CE.Global.General.GetUTCDateTime();
                        string nationality = "";
                        string relationship = "";

                        NoOfTravellers = Convert.ToInt32(txtNoOfTravellers.Text.Trim());

                        TATravellersToInsure _tatravellerstoinsure = new TATravellersToInsure();
                        TATravellersToInsureDB _tatravellerstoinsuredb = new TATravellersToInsureDB();


                        for (int i = 1; i <= NoOfTravellers; i++)
                        {
                            if (_InsuredType == "IND")
                            {
                                if (i == 1)
                                {
                                    surname = txtNameOfInsured.Text.ToUpper();
                                    givenname = txtNameOfInsuredGiven.Text.ToUpper();
                                    idnum = ddlNRIC.GetIdNumber();//txtNRICPass.Text;
                                    birthday = usrDOB.GetDate();
                                    nationality = ddlNationality.GetNationality();
                                    relationship = ddlRelationship.Text;
                                }

                            }
                            else if (_InsuredType == "INS")
                            {
                                if (i == 1)
                                {
                                    surname = txtInsured.Text.ToUpper();
                                    givenname = txtInsuredGiven.Text.ToUpper();
                                    idnum = ddlNRICInsured.GetIdNumber();//txtNRICPass.Text;
                                    birthday = usrDOBinsured.GetDate();
                                    nationality = ddlNationality.GetNationality();
                                    relationship = ddlRelationship.Text;
                                }
                                if (i == 2)
                                {
                                    surname = txtSpouse.Text.ToUpper();
                                    givenname = txtSpouseGiven.Text.ToUpper();
                                    idnum = ddlNRICSpouse.GetIdNumber();// txtNRICPassSpouse.Text;
                                    birthday = usrDOBSpouse.GetDate();
                                    nationality = ddlNationality.GetNationality();
                                    relationship = "Spouse";
                                }
                            }
                            else //Family
                            {
                                if (txtNoOfAdult.Text.Trim() == "1") //Individual+Child
                                {
                                    if (i == 1)
                                    {
                                        surname = txtNameOfInsured.Text.ToUpper();
                                        givenname = txtNameOfInsuredGiven.Text.ToUpper();
                                        idnum = ddlNRIC.GetIdNumber();//txtNRICPass.Text;
                                        birthday = usrDOB.GetDate();
                                        nationality = ddlNationality.GetNationality();
                                        relationship = ddlRelationship.Text;
                                    }
                                    if (i == 2)
                                    {
                                        surname = txtChildName1.Text.ToUpper();
                                        givenname = txtChildName1Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber1.GetIdNumber();
                                        birthday = ddlChildDOB1.GetDate();
                                        relationship = "Child";
                                    }
                                    if (i == 3)
                                    {
                                        surname = txtChildName2.Text.ToUpper();
                                        givenname = txtChildName2Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber2.GetIdNumber();
                                        birthday = ddlChildDOB2.GetDate();
                                        relationship = "Child";
                                    }
                                    if (i == 4)
                                    {
                                        surname = txtChildName3.Text.ToUpper();
                                        givenname = txtChildName3Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber3.GetIdNumber();
                                        birthday = ddlChildDOB3.GetDate();
                                        relationship = "Child";
                                    }
                                    if (i == 5)
                                    {
                                        surname = txtChildName4.Text.ToUpper();
                                        givenname = txtChildName4Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber4.GetIdNumber();
                                        birthday = ddlChildDOB4.GetDate();
                                        relationship = "Child";
                                    }
                                    if (i == 6)
                                    {
                                        surname = txtChildName5.Text.ToUpper();
                                        givenname = txtChildName5Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber5.GetIdNumber();
                                        birthday = ddlChildDOB5.GetDate();
                                        relationship = "Child";
                                    }
                                    if (i == 7)
                                    {
                                        surname = txtChildName6.Text.ToUpper();
                                        givenname = txtChildName5Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber6.GetIdNumber();
                                        birthday = ddlChildDOB6.GetDate();
                                        relationship = "Child";
                                    }
                                }
                                else
                                {
                                    if (i == 1)
                                    {
                                        surname = txtInsured.Text.ToUpper();
                                        givenname = txtInsuredGiven.Text.ToUpper();
                                        idnum = ddlNRICInsured.GetIdNumber();//txtNRICPass.Text;
                                        birthday = usrDOBinsured.GetDate();
                                        nationality = ddlNationality.GetNationality();
                                        relationship = ddlRelationship.Text;
                                    }
                                    if (i == 2)
                                    {
                                        surname = txtSpouse.Text.ToUpper();
                                        givenname = txtSpouseGiven.Text.ToUpper();
                                        idnum = ddlNRICSpouse.GetIdNumber();// txtNRICPassSpouse.Text;
                                        birthday = usrDOBSpouse.GetDate();
                                        nationality = ddlNationality.GetNationality();
                                        relationship = "Spouse";
                                    }

                                    if (i == 3)
                                    {
                                        surname = txtChildName1.Text.ToUpper();
                                        givenname = txtChildName1Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber1.GetIdNumber();
                                        birthday = ddlChildDOB1.GetDate();
                                        relationship = "Child";
                                    }
                                    if (i == 4)
                                    {
                                        surname = txtChildName2.Text.ToUpper();
                                        givenname = txtChildName2Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber2.GetIdNumber();
                                        birthday = ddlChildDOB2.GetDate();
                                        relationship = "Child";
                                    }
                                    if (i == 5)
                                    {
                                        surname = txtChildName3.Text.ToUpper();
                                        givenname = txtChildName3Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber3.GetIdNumber();
                                        birthday = ddlChildDOB3.GetDate();
                                        relationship = "Child";
                                    }
                                    if (i == 6)
                                    {
                                        surname = txtChildName4.Text.ToUpper();
                                        givenname = txtChildName4Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber4.GetIdNumber();
                                        birthday = ddlChildDOB4.GetDate();
                                        relationship = "Child";
                                    }
                                    if (i == 7)
                                    {
                                        surname = txtChildName5.Text.ToUpper();
                                        givenname = txtChildName5Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber5.GetIdNumber();
                                        birthday = ddlChildDOB5.GetDate();
                                        relationship = "Child";
                                    }
                                    if (i == 8)
                                    {
                                        surname = txtChildName6.Text.ToUpper();
                                        givenname = txtChildName6Given.Text.ToUpper();
                                        idnum = ddlChildIdNumber6.GetIdNumber();
                                        birthday = ddlChildDOB6.GetDate();
                                        relationship = "Child";
                                    }
                                }
                            }


                            _tatravellerstoinsure.TATraId = 0;
                            //_tatravellerstoinsure.TAPersonnelId = _tapersonnel.TAPersonnelId;
                            _tatravellerstoinsure.TAPersonnelId = _tamoreresult;
                            _tatravellerstoinsure.ProviderCompanyId = 36;
                            _tatravellerstoinsure.Salutation = salutation;
                            _tatravellerstoinsure.Fullname = givenname + " " + surname;
                            _tatravellerstoinsure.IDType = idtype;
                            _tatravellerstoinsure.IDNumber = idnum;
                            _tatravellerstoinsure.Gender = gender;
                            _tatravellerstoinsure.Birthday = birthday;
                            _tatravellerstoinsure.Nationality = nationality;
                            _tatravellerstoinsure.Relationship = relationship;
                            _tatravellerstoinsure.Info1 = "ACE";

                            if (Session[General.UserId] != null)
                                _tatravellerstoinsure.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                            else
                                _tatravellerstoinsure.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());

                            _tatravellerstoinsure.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                            _tatravellerstoinsure.Status = true;

                            TATraId = _tatravellerstoinsuredb.Insert(_tatravellerstoinsure);

                        }

                    }
                }

                if (TATraId > 0)
                {
                    ProposalNotification();
                    UserConfirmation _userconfirm = new UserConfirmation();
                    UserConfirmationDB _userconfirmdb = new UserConfirmationDB();
                    _userconfirm.ConfirmationType = "TA";
                    _userconfirm.CurrentStep = 2;
                    _userconfirm.FirstStepId = Convert.ToInt64(Session[General.TAId].ToString());

                    if (Session[General.UserId] != null)
                        _userconfirm.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                    else
                        _userconfirm.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());

                    _userconfirm.Status = true;
                    _userconfirm.IsConfirm = true;
                    _userconfirm.ResultStatus = "Complete";
                    _userconfirm.IsComplete = true;
                    Int64 _result = _userconfirmdb.Insert(_userconfirm);
                    if (_result > 0)
                    {
                        string _providerid = Encode(Session[General.ProviderCompanyId].ToString());
                        string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));
                        string _RefNo = "TIA" + convertno;

                        General.ClearAllSession(this.Page, "ALL");
                        Response.Redirect("~/travel-insurance/usermessage.aspx?pcid=" + _providerid + "&ref=" + _RefNo);
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowMessage", "alert(\"Can't update confirmation status.\"", true);
                    }
                }
            }
            else
            {
                lblMessage.Text = _acemessage[0] + ": " + _acemessage[1];

            }


            //Log Ace WS Response
            TAAceResponse _aceresponse = new TAAceResponse();
            TAAceResponseDB _aceresponsedb = new TAAceResponseDB();

            _aceresponse.AceResponseId = 0;
            _aceresponse.CETAInsId = Convert.ToInt64(Session[General.TAResultId].ToString());
            _aceresponse.CETAId = Convert.ToInt64(Session[General.TAId].ToString()); //TAAppSeaID 
            _aceresponse.AceResponse = _acemessage[0] + ": " + _acemessage[1];
            if (Session[General.UserId] != null)
                _aceresponse.RefCEUserid = Convert.ToInt64(Session[General.UserId].ToString());
            else
                _aceresponse.RefCEUserid = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());


            _aceresponsedb.Insert(_aceresponse);
        }
    }

    private string[] SendToACE(bool isIndividualSpouse)
    {
        string[] _aceMessage = new string[2];

        //ACE WEBSERVICE
        #region acewebserv

        int noOfLoop = 1;

        if (isIndividualSpouse)
            noOfLoop = 2;

        for (int n = 1; n <= noOfLoop; n++)
        {
            ACORDService _acService = new ACORDService();

            string acesalutation = ddlSalutation.GetSalutation();
            DateTime dtstart = Convert.ToDateTime(lblStart.Text);
            DateTime dtend = Convert.ToDateTime(lblEnd.Text);


            //POLICY REQUEST

            _PlanName = inPlanName.Value.Trim();
            _TripType = inTripType.Value.Trim();
            _CountryID = Convert.ToInt64(inCountryId.Value.Trim());
            _InsuredType = inInsuredType.Value.Trim();
            _AreaID = Convert.ToInt64(inAreaId.Value.Trim());

            ACORD2 _reqACORD2 = new ACORD2();
            _reqACORD2.SignonRq = new ACORDSignonRq1();
            _reqACORD2.SignonRq.ClientApp = new ACORDSignonRqClientApp1();

            _reqACORD2.SignonRq.ClientApp.Name = "ATI SG";
            _reqACORD2.SignonRq.ClientApp.Org = "sg.gov.ATI";
            _reqACORD2.SignonRq.ClientApp.Version = 1;

            _reqACORD2.SignonRq.ClientDt = CE.Global.General.GetUTCDateTime();
            _reqACORD2.SignonRq.SignonPswd = new ACORDSignonRqSignonPswd1();
            _reqACORD2.SignonRq.SignonPswd.CustId = new ACORDSignonRqSignonPswdCustId1();
            //_reqACORD2.SignonRq.SignonPswd.CustId.CustLoginId = "ati.svc"; //TEST 
            _reqACORD2.SignonRq.SignonPswd.CustId.CustLoginId = "cei.svc"; //LIVE
            _reqACORD2.SignonRq.SignonPswd.CustId.SPName = "sg.gov.ATI";
            _reqACORD2.SignonRq.SignonPswd.CustPswd = new ACORDSignonRqSignonPswdCustPswd1();
            _reqACORD2.SignonRq.SignonPswd.CustPswd.EncryptionTypeCd = ACORDSignonRqSignonPswdCustPswdEncryptionTypeCd1.None;
            //_reqACORD2.SignonRq.SignonPswd.CustPswd.Pswd = "password";  //TEST
            _reqACORD2.SignonRq.SignonPswd.CustPswd.Pswd = "c0mp@R33xSvc!";  //LIVE
            _reqACORD2.SignonRq.CustLangPref = "en-US";

            _reqACORD2.InsuranceSvcRq = new ACORDInsuranceSvcRq1();
            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq = new ACORDInsuranceSvcRqPersPkgPolicyAddRq();
            //_reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.RqUID = "03a84772-b270-4110-8d12-6665d4bf99fb";
            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.TransactionRequestDt = CE.Global.General.GetUTCDateTime();
            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.InsuredOrPrincipal = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipal();
            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.InsuredOrPrincipal.GeneralPartyInfo = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfo();

            ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoAddr[] _reqArrAddrInfo = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoAddr[1];
            ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoAddr _reqAddreInfo = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoAddr();

            _reqAddreInfo.Addr1 = txtAddress.Text;
            _reqAddreInfo.Addr2 = txtUnit1.Text + "-" + txtUnit2.Text;
            _reqAddreInfo.Addr3 = "Singapore " + txtPostCode.Text;
            _reqAddreInfo.City = "Singapore";
            _reqAddreInfo.Country = "Singapore";
            _reqAddreInfo.id = "1";
            _reqAddreInfo.PostalCode = txtPostCode.Text;
            //_reqAddreInfo.NameInfoRef = "CompareXpress";
            _reqAddreInfo.StateProv = "Singapore";
            _reqArrAddrInfo.SetValue(_reqAddreInfo, 0);

            ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunications[] _reqArrCommunication = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunications[1];
            ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunications _reqCommunication = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunications();

            ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunicationsEmailInfo _reqEmailInfo = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunicationsEmailInfo();
            ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunicationsEmailInfo[] _reqArrEmailInfo = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunicationsEmailInfo[1];

            _reqEmailInfo.EmailAddr = txtEmailAddress.Text; // "cherylmae.lanot@teledirect.com.sg";
            _reqArrEmailInfo.SetValue(_reqEmailInfo, 0);

            ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunicationsPhoneInfo _reqPhoneInfo = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunicationsPhoneInfo();
            ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunicationsPhoneInfo[] _reqArrPhoneInfo = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunicationsPhoneInfo[1];

            _reqPhoneInfo.PhoneNumber = txtMobileNo.GetPhoneNo(); //"84980513";
            _reqPhoneInfo.PhoneTypeCd = ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoCommunicationsPhoneInfoPhoneTypeCd.Cell;
            _reqArrPhoneInfo.SetValue(_reqPhoneInfo, 0);

            _reqCommunication.EmailInfo = _reqArrEmailInfo;
            _reqCommunication.PhoneInfo = _reqArrPhoneInfo;

            _reqArrCommunication.SetValue(_reqCommunication, 0);

            ACORDInsuranceSvcRqPersPkgPolicyAddRqPersPolicy _reqPersPolicy = new ACORDInsuranceSvcRqPersPkgPolicyAddRqPersPolicy();
            //_reqPersPolicy.CompanyProductCd = "16EF7335-2C5F-4437-A594-9E37007E30B2"; //-- Hide 10 Jan 2014
            _reqPersPolicy.CompanyProductCd = "D282DF55-F005-40E8-9378-A143001E128A"; //-- Added 10 Jan 2014

            ACORDInsuranceSvcRqPersPkgPolicyAddRqPersPolicyContractTerm _reqPersContract = new ACORDInsuranceSvcRqPersPkgPolicyAddRqPersPolicyContractTerm();

            _reqPersContract.EffectiveDt = dtstart;
            _reqPersContract.ExpirationDt = dtend;

            _reqPersPolicy.ContractTerm = _reqPersContract;

            ACORDInsuranceSvcRqPersPkgPolicyAddRqPersPolicyComacegroup_Destination _reqDestination = new ACORDInsuranceSvcRqPersPkgPolicyAddRqPersPolicyComacegroup_Destination();

            if (_CountryID == 127) //Malaysia
            {
                _reqDestination.RqUID = "6216C914-81A0-405F-92C5-9E370083D850";
                _reqDestination.DestinationDesc = "Malaysia";
            }
            else if (_CountryID == 251) //Batam
            {
                _reqDestination.RqUID = "6216C914-81A0-405F-92C5-9E370083D850";
                _reqDestination.DestinationDesc = "Indonesia - Batam";
            }
            else if (_CountryID == 252) //Bintan
            {
                _reqDestination.RqUID = "6216C914-81A0-405F-92C5-9E370083D850";
                _reqDestination.DestinationDesc = "Indonesia - Bintan";
            }
            else if (_AreaID == 1) //ASEAN
            {
                _reqDestination.RqUID = "8DDC8B82-C995-44E8-9DED-9D4800950E94";
                _reqDestination.DestinationDesc = "ASEAN";
            }
            else if (_AreaID == 2) //Asia
            {
                _reqDestination.RqUID = "A074E507-884B-462E-9EB0-9DD60083F4F4";
                _reqDestination.DestinationDesc = "Asia";
            }
            else if (_AreaID == 4 || _AreaID == 3) //Worldwide
            {
                _reqDestination.RqUID = "3CD9A999-DB64-4C5D-9932-9DD6008400F3";
                _reqDestination.DestinationDesc = "Worldwide";
            }

            ACORDInsuranceSvcRqPersPkgPolicyAddRqPersPolicyComacegroup_InsuredPackage _reqPackage = new ACORDInsuranceSvcRqPersPkgPolicyAddRqPersPolicyComacegroup_InsuredPackage();

            if (_InsuredType == "FML")
            {
                if (txtNoOfAdult.Text.Trim() == "1") //Individual+Child
                {
                    _reqPackage.RqUID = "6E604A52-A33C-43A9-8B44-9D4800954B74";
                    _reqPackage.InsuredPackageDesc = "Insured & Children";
                }
                else
                {
                    _reqPackage.RqUID = "141BB1CF-297E-4388-8E80-9CCD00578344";
                    _reqPackage.InsuredPackageDesc = "Family";
                }
            }
            else //individual /individual+spouse
            {
                _reqPackage.RqUID = "851CFFF2-ED6E-4835-A7FD-9D0D0019C474";
                _reqPackage.InsuredPackageDesc = "Individual";
            }


            ACORDInsuranceSvcRqPersPkgPolicyAddRqPersPolicyComacegroup_Plan _reqPlan = new ACORDInsuranceSvcRqPersPkgPolicyAddRqPersPolicyComacegroup_Plan();

            if (_PlanName == "Basic")
            {
                _reqPlan.RqUID = "9F2AA3B1-660A-467F-8040-9E3700834C25";

            }
            else if (_PlanName == "Essential" && _TripType == "S")
            {
                _reqPlan.RqUID = "1C6C23CC-7B95-4889-8A90-9DAB007874E9";
            }
            else if (_PlanName == "Ultimate" && _TripType == "S")
            {
                _reqPlan.RqUID = "CDE0C908-851E-4FD3-B553-9E370082DC55";
            }
            else if (_PlanName == "Supreme" && _TripType == "S")
            {
                _reqPlan.RqUID = "2813BE62-BFB5-4E5C-91C7-9E37008335E5";
            }
            else if (_PlanName == "Essential" && _TripType == "A")
            {
                _reqPlan.RqUID = "DD62CB29-FC95-4363-B376-9E3700838E41";
            }
            else if (_PlanName == "Ultimate" && _TripType == "A")
            {
                _reqPlan.RqUID = "D7E0BCC2-BC7A-4C17-8941-9E370083686E";
            }
            else if (_PlanName == "Supreme" && _TripType == "A")
            {
                _reqPlan.RqUID = "C19F77AB-F8DE-45A3-8F1F-9E37008377F3";
            }

            _reqPlan.PlanDesc = _PlanName;

            ACORDInsuranceSvcRqPersPkgPolicyAddRqComacegroup_PaymentProcess _reqPayment = new ACORDInsuranceSvcRqPersPkgPolicyAddRqComacegroup_PaymentProcess();

            PaymentProcess _reqPayProcess = new PaymentProcess();

            PaymentProcessPaymentRequest _reqPayReq = new PaymentProcessPaymentRequest();
            PaymentProcessPaymentRequestCreditCardDetails _reqCC = new PaymentProcessPaymentRequestCreditCardDetails();

            _reqCC.NameOnCard = txtNameoftheCard.Text; // "Ray Tan";

            if (rdoVisa.Checked)
            {
                _reqCC.CardType = PaymentProcessPaymentRequestCreditCardDetailsCardType.Visa;
            }
            else if (rdoMasterCard.Checked)
            {
                _reqCC.CardType = PaymentProcessPaymentRequestCreditCardDetailsCardType.Master;
            }
            //else if (rdoAmex.Checked)
            //{
            //    _reqCC.CardType = PaymentProcessPaymentRequestCreditCardDetailsCardType.Amex;
            //}
            //else if (rdoJcb.Checked)
            //{
            //    _reqCC.CardType = PaymentProcessPaymentRequestCreditCardDetailsCardType.JCB;
            //}
            //else if (rdoDiners.Checked)
            //{
            //    _reqCC.CardType = PaymentProcessPaymentRequestCreditCardDetailsCardType.Diners;
            //}

            _reqCC.CardNumber = txtCardNo1.Text.Trim() + txtCardNo2.Text.Trim() + txtCardNo3.Text.Trim() + txtCardNo4.Text.Trim();
            _reqCC.EncryptionType = PaymentProcessPaymentRequestCreditCardDetailsEncryptionType.None;
            _reqCC.EncryptionTypeSpecified = true;
            _reqCC.SecurityCode = txtSecurity.Text.Trim(); // "1234";
            _reqCC.ExpiryMonth = Convert.ToByte(ddlCardExpiryMonth.Text);
            _reqCC.ExpiryYear = Convert.ToByte(ddlCardExpiryYear.Text.Substring(2, 2));

            _reqPayReq.PaymentModeSpecified = true;
            _reqPayReq.PaymentMode = PaymentProcessPaymentRequestPaymentMode.CreditCard;
            _reqPayReq.TransactionDate = CE.Global.General.GetUTCDateTime();
            _reqPayReq.Currency = PaymentProcessPaymentRequestCurrency.SGD;
            
            if (isIndividualSpouse)
            {
                decimal dpremium = decimal.Parse(lblTotalPremium.Text.Remove(0, 2)) / 2;
                _reqPayReq.Amount = dpremium;
            }
            else
            {
                _reqPayReq.Amount = decimal.Parse(lblTotalPremium.Text.Remove(0, 2));
            }

            _reqPayReq.CreditCardDetails = _reqCC;

            PaymentProcessPaymentResponse _reqPayRes = new PaymentProcessPaymentResponse();
            _reqPayRes.TransactionDate = CE.Global.General.GetUTCDateTime();
            _reqPayRes.ReceiptNumber = "123";

            _reqPayProcess.PaymentRequest = _reqPayReq;
            _reqPayProcess.PaymentResponse = _reqPayRes;

            _reqPayment.PaymentProcess = _reqPayProcess;

            _reqACORD2.InsuranceSvcRq.RqUID = "03a84772-b270-4110-8d12-6665d4bf99fb";

            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.InsuredOrPrincipal.GeneralPartyInfo.Addr = _reqArrAddrInfo;
            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.InsuredOrPrincipal.GeneralPartyInfo.Communications = _reqArrCommunication;

            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.PersPolicy = _reqPersPolicy;
            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.PersPolicy.comacegroup_Destination = _reqDestination;
            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.PersPolicy.comacegroup_InsuredPackage = _reqPackage;
            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.PersPolicy.comacegroup_Plan = _reqPlan;

            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.comacegroup_PaymentProcess = _reqPayment;

            string surname = "";
            string givenname = "";
            string idnum = "";
            DateTime birthday = CE.Global.General.GetUTCDateTime();
            string nationality = "";
            string relationship = "";

            int NoOfTravellers = Convert.ToInt32(txtNoOfTravellers.Text.Trim());
            int adjustNoOfTravellers = NoOfTravellers + 1;

            if (isIndividualSpouse)
                adjustNoOfTravellers = NoOfTravellers;

            ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoNameInfo[] _reqArrNameInfo = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoNameInfo[adjustNoOfTravellers];

            TATravellersToInsure _tatravellerstoinsure = new TATravellersToInsure();
            TATravellersToInsureDB _tatravellerstoinsuredb = new TATravellersToInsureDB();


            for (int i = 1; i <= adjustNoOfTravellers; i++)
            {
                ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoNameInfo _reqNameInfo = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoNameInfo();
                ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoNameInfoPersonName _reqPersonName = new ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoNameInfoPersonName();

                if (_InsuredType == "IND")
                {
                    if (i == 1)
                    {
                        surname = txtSurname.Text.ToUpper();
                        givenname = txtFirstname.Text.ToUpper();
                        idnum = ddlNRICPolicyHolder.GetIdNumber();
                        birthday = usrDOBPolicyHolder.GetDate();
                        nationality = ddlNationality.GetNationality();
                        relationship = "Policy Holder";
                    }

                    if (i == 2)
                    {
                        surname = txtNameOfInsured.Text.ToUpper();
                        givenname = txtNameOfInsuredGiven.Text.ToUpper();
                        idnum = ddlNRIC.GetIdNumber();
                        birthday = usrDOB.GetDate();
                        nationality = ddlNationality.GetNationality();
                        relationship = ddlRelationship.Text;

                    }
                }
                else if (_InsuredType == "INS")
                {
                    if (n == 1) //1st Insured
                    {
                        if (i == 1)
                        {
                            surname = txtSurname.Text.ToUpper();
                            givenname = txtFirstname.Text.ToUpper();
                            idnum = ddlNRICPolicyHolder.GetIdNumber();
                            birthday = usrDOBPolicyHolder.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = "Policy Holder";
                        }
                        if (i == 2)
                        {
                            surname = txtInsured.Text.ToUpper();
                            givenname = txtInsuredGiven.Text.ToUpper();
                            idnum = ddlNRICInsured.GetIdNumber();
                            birthday = usrDOBinsured.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = ddlRelationshipWithSpouse.Text;
                        }
                    }
                    else //Spouse
                    {
                        if (i == 1)
                        {
                            surname = txtSurname.Text.ToUpper();
                            givenname = txtFirstname.Text.ToUpper();
                            idnum = ddlNRICPolicyHolder.GetIdNumber();
                            birthday = usrDOBPolicyHolder.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = "Policy Holder";

                        }
                        if (i == 2)
                        {
                            surname = txtSpouse.Text.ToUpper();
                            givenname = txtSpouseGiven.Text.ToUpper();
                            idnum = ddlNRICSpouse.GetIdNumber();
                            birthday = usrDOBSpouse.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = "Spouse";
                        }
                    }
                }
                else if (_InsuredType == "FML") //Family
                {
                    if (txtNoOfAdult.Text.Trim() == "1") //Individual+Child
                    {
                        if (i == 1)
                        {
                            surname = txtSurname.Text.ToUpper();
                            givenname = txtFirstname.Text.ToUpper();
                            idnum = ddlNRICPolicyHolder.GetIdNumber();
                            birthday = usrDOBPolicyHolder.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = "Policy Holder";

                        }
                        if (i == 2)
                        {
                            surname = txtNameOfInsured.Text.ToUpper();
                            givenname = txtNameOfInsuredGiven.Text.ToUpper();
                            idnum = ddlNRIC.GetIdNumber();
                            birthday = usrDOB.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = ddlRelationship.Text;

                        }
                        if (i == 3)
                        {
                            surname = txtChildName1.Text.ToUpper();
                            givenname = txtChildName1Given.Text.ToUpper();
                            idnum = ddlChildIdNumber1.GetIdNumber();
                            birthday = ddlChildDOB1.GetDate();
                            relationship = "Child";

                        }
                        if (i == 4)
                        {
                            surname = txtChildName2.Text.ToUpper();
                            givenname = txtChildName2Given.Text.ToUpper();
                            idnum = ddlChildIdNumber2.GetIdNumber();
                            birthday = ddlChildDOB2.GetDate();
                            relationship = "Child";
                        }
                        if (i == 5)
                        {
                            surname = txtChildName3.Text.ToUpper();
                            givenname = txtChildName3Given.Text.ToUpper();
                            idnum = ddlChildIdNumber3.GetIdNumber();
                            birthday = ddlChildDOB3.GetDate();
                            relationship = "Child";
                        }
                        if (i == 6)
                        {

                            surname = txtChildName4.Text.ToUpper();
                            givenname = txtChildName4Given.Text.ToUpper();
                            idnum = ddlChildIdNumber4.GetIdNumber();
                            birthday = ddlChildDOB4.GetDate();
                            relationship = "Child";

                        }
                        if (i == 7)
                        {

                            surname = txtChildName5.Text.ToUpper();
                            givenname = txtChildName5Given.Text.ToUpper();
                            idnum = ddlChildIdNumber5.GetIdNumber();
                            birthday = ddlChildDOB5.GetDate();
                            relationship = "Child";

                        }
                        if (i == 8)
                        {
                            surname = txtChildName6.Text.ToUpper();
                            givenname = txtChildName5Given.Text.ToUpper();
                            idnum = ddlChildIdNumber6.GetIdNumber();
                            birthday = ddlChildDOB6.GetDate();
                            relationship = "Child";
                        }
                    }
                    else
                    {
                        if (i == 1)
                        {
                            surname = txtSurname.Text.ToUpper();
                            givenname = txtFirstname.Text.ToUpper();
                            idnum = ddlNRICPolicyHolder.GetIdNumber();
                            birthday = usrDOBPolicyHolder.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = "Policy Holder";
                        }
                        if (i == 2)
                        {
                            surname = txtInsured.Text.ToUpper();
                            givenname = txtInsuredGiven.Text.ToUpper();
                            idnum = ddlNRICInsured.GetIdNumber();
                            birthday = usrDOBinsured.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = ddlRelationshipWithSpouse.Text;
                        }
                        if (i == 3)
                        {
                            surname = txtSpouse.Text.ToUpper();
                            givenname = txtSpouseGiven.Text.ToUpper();
                            idnum = ddlNRICSpouse.GetIdNumber();
                            birthday = usrDOBSpouse.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = "Spouse";
                        }

                        if (i == 4)
                        {
                            surname = txtChildName1.Text.ToUpper();
                            givenname = txtChildName1Given.Text.ToUpper();
                            idnum = ddlChildIdNumber1.GetIdNumber();
                            birthday = ddlChildDOB1.GetDate();
                            relationship = "Child";
                        }
                        if (i == 5)
                        {
                            surname = txtChildName2.Text.ToUpper();
                            givenname = txtChildName2Given.Text.ToUpper();
                            idnum = ddlChildIdNumber2.GetIdNumber();
                            birthday = ddlChildDOB2.GetDate();
                            relationship = "Child";
                        }
                        if (i == 6)
                        {
                            surname = txtChildName3.Text.ToUpper();
                            givenname = txtChildName3Given.Text.ToUpper();
                            idnum = ddlChildIdNumber3.GetIdNumber();
                            birthday = ddlChildDOB3.GetDate();
                            relationship = "Child";
                        }
                        if (i == 7)
                        {
                            surname = txtChildName4.Text.ToUpper();
                            givenname = txtChildName4Given.Text.ToUpper();
                            idnum = ddlChildIdNumber4.GetIdNumber();
                            birthday = ddlChildDOB4.GetDate();
                            relationship = "Child";
                        }
                        if (i == 8)
                        {
                            surname = txtChildName5.Text.ToUpper();
                            givenname = txtChildName5Given.Text.ToUpper();
                            idnum = ddlChildIdNumber5.GetIdNumber();
                            birthday = ddlChildDOB5.GetDate();
                            relationship = "Child";
                        }
                        if (i == 9)
                        {
                            surname = txtChildName6.Text.ToUpper();
                            givenname = txtChildName5Given.Text.ToUpper();
                            idnum = ddlChildIdNumber6.GetIdNumber();
                            birthday = ddlChildDOB6.GetDate();
                            relationship = "Child";
                        }
                    }
                }

                _reqPersonName.Surname = surname;
                _reqPersonName.GivenName = givenname;

                _reqNameInfo.PersonName = _reqPersonName;
                _reqNameInfo.BirthDt = birthday;

                if (i == 1)
                {
                    _reqPersonName.TitlePrefix = acesalutation;

                    if (acesalutation == "Mr" || acesalutation == "Dr")
                    {
                        _reqNameInfo.Gender = ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoNameInfoGender.M;
                    }
                    else
                    {
                        _reqNameInfo.Gender = ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoNameInfoGender.F;
                    }

                    _reqNameInfo.GenderSpecified = true;
                }

                _reqNameInfo.id = i.ToString();
                _reqNameInfo.IdNumber = idnum; // "S1234567D";
                _reqNameInfo.IdNumberTypeCd = ACORDInsuranceSvcRqPersPkgPolicyAddRqInsuredOrPrincipalGeneralPartyInfoNameInfoIdNumberTypeCd.IDNumber;
                _reqNameInfo.IdNumberTypeCdSpecified = true;

                _reqNameInfo.TitleRelationshipDesc = relationship;


                _reqArrNameInfo.SetValue(_reqNameInfo, i - 1);

            }

            _reqACORD2.InsuranceSvcRq.PersPkgPolicyAddRq.InsuredOrPrincipal.GeneralPartyInfo.NameInfo = _reqArrNameInfo;
            ACORD3 _resACORD3 = _acService.GetTravelPolicy(_reqACORD2);

            _aceMessage[0] = _resACORD3.InsuranceSvcRs.PersPkgPolicyAddRs.MsgStatus.MsgStatusCd.ToString();
            _aceMessage[1] = _resACORD3.InsuranceSvcRs.PersPkgPolicyAddRs.MsgStatus.MsgStatusDesc.ToString();


            if (_aceMessage[0] != "Success" && _aceMessage[1] != "Policy Accepted")
            {
                break;
            }
        }

        #endregion

        return _aceMessage;
    }

    public string Encode(string sData)
    {
        byte[] encData_byte = new byte[sData.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
        string encodedData = Convert.ToBase64String(encData_byte);
        return encodedData;
    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("TA", Request, "Travel Insurance applicant's details.");
    }

    private void CheckValidation()
    {
        int NoOfTravellers = Convert.ToInt32(lblNoOfTravellers.Text.ToString());

        usrDOBPolicyHolder.IsEnableValidation(true);
        ddlNRICPolicyHolder.IsEnableValidation(true);

        usrDOB.IsEnableValidation(false);
        usrDOBinsured.IsEnableValidation(false);
        usrDOBSpouse.IsEnableValidation(false);

        if (divIndividual.Visible == true)
        {
            usrDOB.IsEnableValidation(true);
            ddlNRIC.IsEnableValidation(true);
        }
        else if (divWithspouse.Visible == true)
        {
            usrDOBinsured.IsEnableValidation(true);
            usrDOBSpouse.IsEnableValidation(true);
            ddlNRICInsured.IsEnableValidation(true);
            ddlNRICSpouse.IsEnableValidation(true);

        }

        txtPostCode.Text = General.ClearScriptTag(txtPostCode.Text);
        txtUnit1.Text = General.ClearScriptTag(txtUnit1.Text);
        txtUnit2.Text = General.ClearScriptTag(txtUnit2.Text);
        txtAddress.Text = General.ClearScriptTag(txtAddress.Text);

        //txtBank.Text = General.ClearScriptTag(txtBank.Text);
        //txtChequeNo.Text = General.ClearScriptTag(txtChequeNo.Text);
        txtNameoftheCard.Text = General.ClearScriptTag(txtNameoftheCard.Text);
        txtIssuingBank.Text = General.ClearScriptTag(txtIssuingBank.Text);
        txtCardNo1.Text = General.ClearScriptTag(txtCardNo1.Text);
        txtCardNo2.Text = General.ClearScriptTag(txtCardNo2.Text);
        txtCardNo3.Text = General.ClearScriptTag(txtCardNo3.Text);
        txtCardNo4.Text = General.ClearScriptTag(txtCardNo4.Text);
        //txtCardExpiryMonth.Text = General.ClearScriptTag(txtCardExpiryMonth.Text);
        //txtCardExpiryYear.Text = General.ClearScriptTag(txtCardExpiryYear.Text);

        //#region Payment Mode
        //if (rdoCashorNets.Checked)
        //{
        //    rfvBank.Enabled = false;
        //    rfvChequeNo.Enabled = false;
        //    revChequeNo.Enabled = false;
        //    rfvNameoftheCard.Enabled = false;
        //    rfvIssuingBank.Enabled = false;
        //    rfvCardNo1.Enabled = false;
        //    revCardNo1.Enabled = false;
        //    rfvCardNo2.Enabled = false;
        //    revCardNo2.Enabled = false;
        //    rfvCardNo3.Enabled = false;
        //    revCardNo3.Enabled = false;
        //    rfvCardNo4.Enabled = false;
        //    revCardNo4.Enabled = false;
        //    rfvCardExpiryMonth.Enabled = false;
        //    revCardExpiryMonth.Enabled = false;
        //    rfvCardExpiryYear.Enabled = false;
        //    revCardExpiryYear.Enabled = false;
        //    rfvCardType.Enabled = false;
        //}
        //else if (rdoCheque.Checked)
        //{
        //    rfvBank.Enabled = true;
        //    rfvChequeNo.Enabled = true;
        //    revChequeNo.Enabled = true;
        //    rfvNameoftheCard.Enabled = false;
        //    rfvIssuingBank.Enabled = false;
        //    rfvCardNo1.Enabled = false;
        //    revCardNo1.Enabled = false;
        //    rfvCardNo2.Enabled = false;
        //    revCardNo2.Enabled = false;
        //    rfvCardNo3.Enabled = false;
        //    revCardNo3.Enabled = false;
        //    rfvCardNo4.Enabled = false;
        //    revCardNo4.Enabled = false;
        //    rfvCardExpiryMonth.Enabled = false;
        //    revCardExpiryMonth.Enabled = false;
        //    rfvCardExpiryYear.Enabled = false;
        //    revCardExpiryYear.Enabled = false;
        //    rfvCardType.Enabled = false;
        //}
        //else if (rdoCreditCard.Checked)
        //{
        //    rfvBank.Enabled = false;
        //    rfvChequeNo.Enabled = false;
        //    revChequeNo.Enabled = false;
        //    rfvNameoftheCard.Enabled = true;
        //    rfvIssuingBank.Enabled = true;
        //    rfvCardNo1.Enabled = true;
        //    revCardNo1.Enabled = true;
        //    rfvCardNo2.Enabled = true;
        //    revCardNo2.Enabled = true;
        //    rfvCardNo3.Enabled = true;
        //    revCardNo3.Enabled = true;
        //    rfvCardNo4.Enabled = true;
        //    revCardNo4.Enabled = true;
        //    rfvCardExpiryMonth.Enabled = true;
        //    revCardExpiryMonth.Enabled = true;
        //    rfvCardExpiryYear.Enabled = true;
        //    revCardExpiryYear.Enabled = true;
        //    rfvCardType.Enabled = true;
        //}
        //#endregion
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        #region Particulars of Proposer

        ddlSalutation.ChangeValidationEffectServerSide(strValidationGroup);

        if (rfvFirstname.Enabled && rfvFirstname.ValidationGroup == strValidationGroup)
        {
            rfvFirstname.Validate();
            if (rfvFirstname.IsValid == false)
            {
                txtFirstname.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtFirstname.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtFirstname.ControlStyle.CssClass = "";
        }


        if (rfvSurname.Enabled && rfvSurname.ValidationGroup == strValidationGroup)
        {
            rfvSurname.Validate();
            if (rfvSurname.IsValid == false)
            {
                txtSurname.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtSurname.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtSurname.ControlStyle.CssClass = "";
        }

        if (revEmailAddress.Enabled && revEmailAddress.ValidationGroup == strValidationGroup)
        {
            if (rfvEmailAddress.IsValid)
            {
                revEmailAddress.Validate();
                if (revEmailAddress.IsValid == false)
                {
                    txtEmailAddress.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtEmailAddress.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtEmailAddress.ControlStyle.CssClass = "";

        }

        //usrGEnder.ChangeValidationEffectServerSide(strValidationGroup);
        //usrIdType.ChangeValidationEffectServerSide(strValidationGroup);
        //usrIdNumber.ChangeValidationEffectServerSide(strValidationGroup);
        ddlNationality.ChangeValidationEffectServerSide(strValidationGroup);
        txtMobileNo.ChangeValidationEffectServerSide(strValidationGroup);
        txtOfficeNo.ChangeValidationEffectServerSide(strValidationGroup);
        txtResidentialPhoneNo.ChangeValidationEffectServerSide(strValidationGroup);

        usrDOBPolicyHolder.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOB.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOBinsured.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOBSpouse.ChangeValidationEffectServerSide(strValidationGroup);

        ddlNRICPolicyHolder.ChangeValidationEffectServerSide(strValidationGroup);
        ddlNRIC.ChangeValidationEffectServerSide(strValidationGroup);
        ddlNRICInsured.ChangeValidationEffectServerSide(strValidationGroup);
        ddlNRICSpouse.ChangeValidationEffectServerSide(strValidationGroup);


        #endregion

        #region Payment Mode

        ////Payment Mode

        //Name of the Card
        if (rfvNameoftheCard.Enabled && rfvNameoftheCard.ValidationGroup == strValidationGroup)
        {
            rfvNameoftheCard.Validate();
            if (rfvNameoftheCard.IsValid == false)
            {
                txtNameoftheCard.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNameoftheCard.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNameoftheCard.ControlStyle.CssClass = "";
        }
        //Issuing Bank
        if (rfvIssuingBank.Enabled && rfvIssuingBank.ValidationGroup == strValidationGroup)
        {
            rfvIssuingBank.Validate();
            if (rfvIssuingBank.IsValid == false)
            {
                txtIssuingBank.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtIssuingBank.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtIssuingBank.ControlStyle.CssClass = "";
        }
        //Card 1
        if (rfvCardNo1.Enabled && rfvCardNo1.ValidationGroup == strValidationGroup)
        {
            rfvCardNo1.Validate();
            if (rfvCardNo1.IsValid == false)
            {
                txtCardNo1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo1.ControlStyle.CssClass = "";
        }

        if (revCardNo1.Enabled && revCardNo1.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo1.IsValid)
            {
                revCardNo1.Validate();
                if (revCardNo1.IsValid == false)
                {
                    txtCardNo1.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo1.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo1.ControlStyle.CssClass = "";
        }
        //Card 2
        if (rfvCardNo2.Enabled && rfvCardNo2.ValidationGroup == strValidationGroup)
        {
            rfvCardNo2.Validate();
            if (rfvCardNo2.IsValid == false)
            {
                txtCardNo2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo2.ControlStyle.CssClass = "";
        }

        if (revCardNo2.Enabled && revCardNo2.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo2.IsValid)
            {
                revCardNo2.Validate();
                if (revCardNo2.IsValid == false)
                {
                    txtCardNo2.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo2.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo2.ControlStyle.CssClass = "";
        }
        //Card 3
        if (rfvCardNo3.Enabled && rfvCardNo3.ValidationGroup == strValidationGroup)
        {
            rfvCardNo3.Validate();
            if (rfvCardNo3.IsValid == false)
            {
                txtCardNo3.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo3.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo3.ControlStyle.CssClass = "";
        }

        if (revCardNo3.Enabled && revCardNo3.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo3.IsValid)
            {
                revCardNo3.Validate();
                if (revCardNo3.IsValid == false)
                {
                    txtCardNo3.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo3.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo3.ControlStyle.CssClass = "";
        }
        //Card 4
        if (rfvCardNo4.Enabled && rfvCardNo4.ValidationGroup == strValidationGroup)
        {
            rfvCardNo4.Validate();
            if (rfvCardNo4.IsValid == false)
            {
                txtCardNo4.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo4.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo4.ControlStyle.CssClass = "";
        }

        if (revCardNo4.Enabled && revCardNo4.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo4.IsValid)
            {
                revCardNo4.Validate();
                if (revCardNo4.IsValid == false)
                {
                    txtCardNo4.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo4.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo4.ControlStyle.CssClass = "";
        }
        //Card Expiry Month
        if (rfvCardExpiryMonth.Enabled && rfvCardExpiryMonth.ValidationGroup == strValidationGroup)
        {
            rfvCardExpiryMonth.Validate();
            if (rfvCardExpiryMonth.IsValid == false)
            {
                ddlCardExpiryMonth.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlCardExpiryMonth.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlCardExpiryMonth.ControlStyle.CssClass = "";
        }


        //Card Expiry Year
        if (rfvCardExpiryYear.Enabled && rfvCardExpiryYear.ValidationGroup == strValidationGroup)
        {
            rfvCardExpiryYear.Validate();
            if (rfvCardExpiryYear.IsValid == false)
            {
                ddlCardExpiryYear.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlCardExpiryYear.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlCardExpiryYear.ControlStyle.CssClass = "";
        }

        //CardType
        if (rfvCardType.Enabled && rfvCardType.ValidationGroup == strValidationGroup)
        {
            rfvCardType.Validate();
            if (rfvCardType.IsValid == false)
            {
                lblVisa.ControlStyle.CssClass = "validationError";
                lblMasterCard.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblVisa.ControlStyle.CssClass = "";
                lblMasterCard.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblVisa.ControlStyle.CssClass = "";
            lblMasterCard.ControlStyle.CssClass = "";
        }

        #endregion

        #region Travellers Info


        if (rfvNameOfInsured.Enabled && rfvNameOfInsured.ValidationGroup == strValidationGroup)
        {
            rfvNameOfInsured.Validate();
            if (rfvNameOfInsured.IsValid == false)
            {
                txtNameOfInsured.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNameOfInsured.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNameOfInsured.ControlStyle.CssClass = "";
        }


        if (rfvInsured.Enabled && rfvInsured.ValidationGroup == strValidationGroup)
        {
            rfvInsured.Validate();
            if (rfvInsured.IsValid == false)
            {
                txtInsured.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtInsured.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtInsured.ControlStyle.CssClass = "";
        }

        if (rfvSpouse.Enabled && rfvSpouse.ValidationGroup == strValidationGroup)
        {
            rfvSpouse.Validate();
            if (rfvSpouse.IsValid == false)
            {
                txtSpouse.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtSpouse.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtSpouse.ControlStyle.CssClass = "";
        }


        if (rfvNoOfChild.Enabled && rfvNoOfChild.ValidationGroup == strValidationGroup)
        {
            rfvNoOfChild.Validate();
            if (rfvNoOfChild.IsValid == false)
            {
                txtNoOfChild.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNoOfChild.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNoOfChild.ControlStyle.CssClass = "";
        }
        #endregion

    }

    protected void csvCreditCardValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        //-------old code-------
        //bool _status = true;
        //string _first = "";

        //if (txtCardNo1.Text.Length > 0)
        //{
        //    _first = txtCardNo1.Text.Trim().Substring(0, 1);
        //}

        //if (rdoVisa.Checked)
        //{
        //    if (_first != "4")
        //    {
        //        _status = false;
        //    }
        //}
        //else if (rdoMasterCard.Checked)
        //{
        //    if (_first != "5")
        //    {
        //        _status = false;
        //    }
        //}
        //if (_status == true)
        //{
        //    txtCreditCardValid.Text = "";
        //    txtCreditCardValid.Text = txtCardNo1.Text.Trim() + "" + txtCardNo2.Text.Trim() + "" + txtCardNo3.Text.Trim() + "" + txtCardNo4.Text.Trim();
        //    string _cardNumer = txtCreditCardValid.Text;
        //    MySecurity _mysecurity = new MySecurity();
        //    if (_mysecurity.IsCreditCardValid(_cardNumer))
        //    {
        //        args.IsValid = true;
        //    }
        //    else
        //    {
        //        args.IsValid = false;
        //    }
        //}
        //else
        //{
        //    args.IsValid = false;
        //}
        //-------old code-------

        txtCreditCardValid.Text = txtCardNo1.Text.Trim() + "" + txtCardNo2.Text.Trim() + "" + txtCardNo3.Text.Trim() + "" + txtCardNo4.Text.Trim();
        string _cardNumber = txtCreditCardValid.Text;

        CardType _cardtype = new CardType();
        if (rdoVisa.Checked)
        {
            _cardtype = CardType.Visa;
        }
        else if (rdoMasterCard.Checked)
        {
            _cardtype = CardType.MasterCard;
        }
        //else if (rdoAmex.Checked)
        //{
        //    _cardtype = CardType.AmericanExpress;
        //}
        //else if (rdoDiners.Checked)
        //{
        //    _cardtype = CardType.DinersClub;
        //}
        //else if (rdoJcb.Checked)
        //{
        //    _cardtype = CardType.JCB;
        //}

        args.IsValid = Validate(_cardtype, _cardNumber);
    }

    protected void csvCCExpiredValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        txtCCExpiredValid.Text = "";
        txtCCExpiredValid.Text = "valid";
        Int32 _Year = Convert.ToInt32(ddlCardExpiryYear.Text);
        Int32 _Month = Convert.ToInt32(ddlCardExpiryMonth.Text);

        MySecurity _mysecurity = new MySecurity();
        if (_mysecurity.IsCreditCardExpiredDateValid(_Year, _Month))
        {
            args.IsValid = true;
        }
        else
        {
            args.IsValid = false;
        }
    }

    private void ClearSession()
    {
        Session[General.TAPersonnelId] = null;
        //Session[General.TAId] = null;
        //Session[General.TAResultId] = null;
    }

    private void ShowUserDetails()
    {
        //hplEditProfile.Visible = true;
        CE.User.Profile _profile = new CE.User.Profile();
        CE.User.ProfileDB _profiledb = new ProfileDB();
        CE.User.Contact _contact = new Contact();
        CE.User.ContactDB _contactdb = new ContactDB();

        Int64 UserId = Convert.ToInt64(Session[General.UserId].ToString());
        _profile = _profiledb.GetProfile(UserId);
        if (_profile != null)
        {

            txtFirstname.Text = _profile.FirstName;
            txtSurname.Text = _profile.SurName;
            txtInsured.Text = _profile.SurName;
            txtInsuredGiven.Text = _profile.FirstName;
            txtNameOfInsured.Text = _profile.SurName;
            txtNameOfInsuredGiven.Text = _profile.FirstName;

            if (_profile.Nationality != "")
            {
                ddlNationality.Nationality = _profile.Nationality.ToString();
            }

            _contact = _contactdb.GetContact(UserId);
            if (_contact != null)
            {
                txtMobileNo.PhoneNo = _contact.Mobile;
                txtOfficeNo.PhoneNo = _contact.OfficePhone;
                txtEmailAddress.Text = _contact.Email.ToString();

            }

            _profile = null;
            _profiledb = null;
            _contact = null;
            _contactdb = null;
        }


    }

    private void ChangeDateSettings()
    {
        usrDOBPolicyHolder.StartYear = CE.Global.General.GetUTCDateTime().Year - 60;
        usrDOBPolicyHolder.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrDOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 60;
        usrDOB.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrDOBSpouse.StartYear = CE.Global.General.GetUTCDateTime().Year - 60;
        usrDOBSpouse.EndYear = CE.Global.General.GetUTCDateTime().Year;

    }

    protected void ibtnBack_Click(object sender, ImageClickEventArgs e)
    {
        //Response.Redirect("travel_quote.aspx");
        Response.Redirect("~/travel-insurance/taresultsquotesone.aspx");
    }

    //protected void Check2NRICValid(object sender, ServerValidateEventArgs args)
    //{
    //    string _appID = txtNRICPassInsured.Text;
    //    string _spouseID = txtNRICPassSpouse.Text;

    //    if (_appID == _spouseID)
    //    {
    //        args.IsValid = false;
    //    }
    //    else
    //    {
    //        args.IsValid = true;
    //    }

    //}

    //protected void Check2NRICValidFamily(object sender, ServerValidateEventArgs args)
    //{
    //    string _appID = txtNRICPassInsuredFamily.Text;
    //    string _spouseID = txtNRICPassSpouseFamily.Text;

    //    if (_appID == _spouseID)
    //    {
    //        args.IsValid = false;
    //    }
    //    else
    //    {
    //        args.IsValid = true;
    //    }

    //}

    private void ProposalNotification()
    {
        string _strSql, _providerName, _providerEmail, _providerCCEmail, _providerBCCEmail, _Date, _Time, _InsuranceName, _RefNo;
        MyDatabase _db = new MyDatabase();
        DataTable _dtProvider = new DataTable();
        DataTable _dtInsurance = new DataTable();
        _Date = "";
        _Time = "";
        _RefNo = "";
        _strSql = "";
        _providerName = "";
        _providerEmail = "";
        _providerCCEmail = "";
        _providerBCCEmail = "";

        _InsuranceName = "Travel Insurance";
        _strSql = "SELECT [CompanyName], [Email1] FROM tblProviderCompany WHERE ProviderCompanyId = " + Session[CE.Global.General.ProviderCompanyId].ToString();
        _dtProvider = _db.GetDataTable(_strSql);

        if (_dtProvider.Rows.Count > 0)
        {
            _providerName = _dtProvider.Rows[0]["CompanyName"].ToString();
        }

        _providerEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ACETI_TO");
        _providerCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ACETI_CC");
        _providerBCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ACETI_BCC");

        _strSql = "";
        _strSql = "SELECT CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time] ";
        _strSql += " FROM  tblTAMoreDetail_Ace WHERE cetaId = " + Session[General.TAId].ToString() + " ORDER BY ModifiedDate DESC";
        _dtInsurance = _db.GetDataTable(_strSql);
        if (_dtInsurance.Rows.Count > 0)
        {
            _Date = _dtInsurance.Rows[0]["Date"].ToString();
            _Time = _dtInsurance.Rows[0]["Time"].ToString();
        }

        string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));
        _RefNo = "TIA" + convertno;

        if ((_dtProvider.Rows.Count > 0) && (_dtInsurance.Rows.Count > 0))
        {
            MyMailManager.SendProposalCompleteNotification(_providerName, _providerEmail, _providerCCEmail, _providerBCCEmail, _InsuranceName, _Date, _Time, _RefNo);
        }

    }

    protected void ibtPostCode_Click(object sender, ImageClickEventArgs e)
    {
        GetPostCode();
    }

    protected void txtPostCode_TextChanged(object sender, EventArgs e)
    {
        GetPostCode();
    }

    protected void ddlAddressList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAddressList.Items.Count > 0 && ddlAddressList.SelectedIndex >= 0)
        {
            txtAddress.Text = ddlAddressList.Text;
        }
    }

    private void GetPostCode()
    {
        rfvPostCode.Validate();
        revPostCode.Validate();
        if (rfvPostCode.IsValid && revPostCode.IsValid)
        {
            txtPostCode.ControlStyle.CssClass = "";
            txtAddress.ControlStyle.CssClass = "";
            MyLocation _myLoc = new MyLocation();
            //string _strAddress = _myLoc.GetAddressByPostCode(txtPostCode.Text);
            //if (_strAddress != null && _strAddress != string.Empty)
            //{
            //    if (_strAddress.ToLower().Contains("invalid api"))
            //    {
            //        txtAddress.Text = "Address can't be retrieved. Please type your address detail here.";
            //    }
            //    else
            //    {
            //        txtAddress.Text = _strAddress;
            //    }
            //}
            //else
            //{
            //    txtAddress.Text = "Address is not found.";
            //}

            System.Data.DataSet _ds = _myLoc.GetAddressByPostCodeDataSet(txtPostCode.Text);
            ddlAddressList.Items.Clear();
            string _lstValue;
            string _lstText;
            int _rowCount = 0;

            if (_ds != null)
            {
                if (_ds.Tables.Count > 0)
                {
                    foreach (System.Data.DataTable _dt in _ds.Tables)
                    {
                        if (_dt.Rows.Count > 0 && _dt.Columns.Count >= 2)
                        {
                            foreach (System.Data.DataRow _dr in _dt.Rows)
                            {
                                //lblAddress2.Text += _dr["t"].ToString() + "<br />";
                                //lblAddress2.Text += _dr["a"].ToString() + "<br /><br />";
                                if (_dr["t"] != null && _dr["a"] != null)
                                {
                                    _lstValue = _dr["t"].ToString() + ", " + _dr["a"].ToString();
                                    _lstText = _dr["t"].ToString();
                                    ddlAddressList.Items.Add(new ListItem(_lstText, _lstValue));
                                    if (_rowCount == 0)
                                    {
                                        txtAddress.Text = _lstValue;
                                        //ibtPostCode.Enabled = false;
                                        txtAddress.ReadOnly = true;
                                    }

                                    _rowCount++;
                                }
                            }
                        }
                        else
                        {
                            txtAddress.Text = "Confirm postcode or enter manually.";
                            txtAddress.ReadOnly = false;
                            txtAddress.ControlStyle.CssClass = "validationError";
                        }
                    }
                }
                else
                {
                    txtAddress.Text = "Confirm postcode or enter manually.";
                    txtAddress.ReadOnly = false;
                    txtAddress.ControlStyle.CssClass = "validationError";
                }
            }
            else
            {
                txtAddress.Text = "Please type your address here.";
                txtAddress.ReadOnly = false;
                txtAddress.ControlStyle.CssClass = "validationError";
            }

            if (_rowCount > 1)
            {
                divAddressList.Visible = true;
            }
            else
            {
                divAddressList.Visible = false;

            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "validationError";
            ddlAddressList.Items.Clear();
            divAddressList.Visible = false;
            txtAddress.Text = "Invalid postcode.";
            txtAddress.ControlStyle.CssClass = "validationError";
        }
    }

    private void ValidateChild1(bool OnOff)
    {
        rfvChildName1.Enabled = OnOff;
        revChildName1.Enabled = OnOff;
        ddlChildIdNumber1.IsEnableValidation(OnOff);
    }

    private void ValidateChild2(bool OnOff)
    {
        rfvChildName2.Enabled = OnOff;
        revChildName2.Enabled = OnOff;
        ddlChildIdNumber2.IsEnableValidation(OnOff);
    }

    private void ValidateChild3(bool OnOff)
    {
        rfvChildName3.Enabled = OnOff;
        revChildName3.Enabled = OnOff;
        ddlChildIdNumber3.IsEnableValidation(OnOff);
    }

    private void ValidateChild4(bool OnOff)
    {
        rfvChildName4.Enabled = OnOff;
        revChildName4.Enabled = OnOff;
        ddlChildIdNumber4.IsEnableValidation(OnOff);
    }

    private void ValidateChild5(bool OnOff)
    {
        rfvChildName5.Enabled = OnOff;
        revChildName5.Enabled = OnOff;
        ddlChildIdNumber5.IsEnableValidation(OnOff);
    }

    private void ValidateChild6(bool OnOff)
    {
        rfvChildName6.Enabled = OnOff;
        revChildName6.Enabled = OnOff;
        ddlChildIdNumber6.IsEnableValidation(OnOff);
    }

    private enum CardType
    {
        MasterCard, BankCard, Visa, AmericanExpress, Discover, DinersClub, JCB
    }

    private bool Validate(CardType cardType, string cardNumber)
    {
        byte[] number = new byte[16]; // number to validate
        int len = 0;
        //len = cardNumber.Length;

        // Remove non-digits      
        for (int i = 0; i < cardNumber.Length; i++)
        {
            if (char.IsDigit(cardNumber, i))
            {
                if (len == 16) return false; // number has too many digits

                number[len++] = byte.Parse(cardNumber[i].ToString());
                //number[len++] = byte.Parse("");
            }
        }

        // Validate based on card type, first if tests length, second tests prefix
        switch (cardType)
        {
            case CardType.MasterCard:
                if (len != 16)
                    return false;
                if (number[0] != 5 || number[1] == 0 || number[1] > 5)
                    return false;
                break;

            case CardType.BankCard:
                if (len != 16)
                    return false;
                if (number[0] != 5 || number[1] != 6 || number[2] > 1)
                    return false;
                break;

            case CardType.Visa:
                if (len != 16 && len != 13)
                    return false;
                if (number[0] != 4)
                    return false;
                break;

            case CardType.AmericanExpress:
                if (len != 15)
                    return false;
                if (number[0] != 3 || (number[1] != 4 && number[1] != 7))
                    return false;
                break;

            case CardType.Discover:
                if (len != 16)
                    return false;
                if (number[0] != 6 || number[1] != 0 || number[2] != 1 || number[3] != 1)
                    return false;
                break;

            case CardType.DinersClub:
                if (len != 14)
                    return false;
                if (number[0] != 3 || (number[1] != 0 && number[1] != 6 && number[1] != 8)
                   || number[1] == 0 && number[2] > 5)
                    return false;
                break;

            case CardType.JCB:
                if (len != 16 && len != 15)
                    return false;
                if (number[0] != 3 || number[1] != 5)
                    return false;
                break;
        }

        // Use Luhn Algorithm to validate
        int sum = 0;
        for (int i = len - 1; i >= 0; i--)
        {
            if (i % 2 == len % 2)
            {
                int n = number[i] * 2;
                sum += (n / 10) + (n % 10);
            }
            else
                sum += number[i];
        }
        return (sum % 10 == 0);
    }

    protected void imgbtnBackTop_Click(object sender, ImageClickEventArgs e)
    {
        //if (Session["acesearch"] != null)
        //{
        //    Response.Redirect("~/ace/result.aspx");
        //}
        //else
        //{
            if (Session["TAFromSummary"] != null)
            {
                if (Session["TAFromSummary"].ToString().Trim() == "1")
                {
                    Response.Redirect("~/travel-insurance/results.aspx");
                }
                else
                {
                    Response.Redirect("~/travel-insurance/results-details.aspx");
                }
            }
            else
            {
                    Response.Redirect("~/travel-insurance/results.aspx");
            }
        //}
    }
}
